package com.sunjs.wechat.controller;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sunjs.model.LyProduct;
import com.sunjs.model.LyProductSort;
import com.sunjs.model.back.RestCode;
import com.sunjs.model.back.RestResponse;
import com.sunjs.wechat.service.WxProductService;

@RestController
@RequestMapping(value = "/wx/product")
public class WxProductController {
	
	@Autowired
	private WxProductService  wxProductService;
	
//	首页展示的商品
	@RequestMapping(value = "/selectShowProduct", method = RequestMethod.POST)
	public RestResponse<List<LyProduct>> selectShowProduct(@RequestBody LyProduct lyProduct) {
		try {
			List<LyProduct> pair = wxProductService.selectShowProduct(lyProduct);
			return  RestResponse.success(pair);
		} catch (Exception e) {
			return RestResponse.error(RestCode.FAIL);
		}
	}
//	搜索之后显示的商品
	@RequestMapping(value = "/selectSearchProduct", method = RequestMethod.POST)
	public RestResponse<List<LyProduct>> selectSearchProduct(@RequestBody LyProduct lyProduct) {
		try {
			List<LyProduct> pair = wxProductService.selectSearchProduct(lyProduct);
			return  RestResponse.success(pair);
		} catch (Exception e) {
			return RestResponse.error(RestCode.FAIL);
		}
	}
	
//	点击更多按钮之后显示的分类id name
//	@RequestMapping(value = "/selectProductSort", method = RequestMethod.POST)
//	public RestResponse<List<LyProductSort>> selectProductSort(@RequestBody LyProductSort lyProductSort) {
//		try {
//			List<LyProductSort> pair = wxProductService.selectProductSort(lyProductSort);
//			return  RestResponse.success(pair);
//		} catch (Exception e) {
//			return RestResponse.error(RestCode.FAIL);
//		}
//	}
	
	
//	id：三级分类id
//	createUser: 1000220006
//	fenyeindex：1
//	sort：1.2.3.4 排序
//	找相似 根据三级id查询所有数据
	@RequestMapping(value = "/selectProductByLevel", method = RequestMethod.POST)
	public RestResponse<List<LyProduct>> selectProductByLevel(@RequestBody LyProductSort lyProductSort) {
		try {
			List<LyProduct> pair = wxProductService.selectProductByLevel(lyProductSort);
			return  RestResponse.success(pair);
		} catch (Exception e) {
			return RestResponse.error(RestCode.FAIL);
		}
	}
	
//	查询分类一级的list
	@RequestMapping(value = "/selectProductSortLevel", method = RequestMethod.POST)
	public RestResponse<List<LyProductSort>> selectProductSortLevel(@RequestBody LyProductSort lyProductSort) {
		try {
			List<LyProductSort> pair = wxProductService.selectProductSortLevel(lyProductSort);
			return  RestResponse.success(pair);
		} catch (Exception e) {
			return RestResponse.error(RestCode.FAIL);
		}
	}
	
//	查询一级分类下二级分类list 三级分类list （没有id默认查询第一个一级id的数据）
	@RequestMapping(value = "/selectProductSortLevelList", method = RequestMethod.POST)
	public RestResponse<List<LyProductSort>> selectProductSortLevelList(@RequestBody LyProductSort lyProductSort) {
		try {
			List<LyProductSort> pair = wxProductService.selectProductSortLevelList(lyProductSort);
			return  RestResponse.success(pair);
		} catch (Exception e) {
			return RestResponse.error(RestCode.FAIL);
		}
	}
	
	
//	根据商品id查询商品的所有详细信息(skuid也是参数)
	@RequestMapping(value = "/selectProductInfo", method = RequestMethod.POST)
	public RestResponse<LyProduct> selectProductInfo(@RequestBody LyProduct lyProduct) {
		try {
			LyProduct pair = wxProductService.selectProductInfo(lyProduct);
			return  RestResponse.success(pair);
		} catch (Exception e) {
			return RestResponse.error(RestCode.FAIL);
		}
	}
	
	
}


